<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<html>
<head>
  <%@ include file="/common/meta.jsp" %>
  <title>流程类型</title>

  <script type="text/javascript">
    var _path = "${_ctx}/flow/processType";

    $(function () {
      $("#layout1").ligerLayout({allowLeftResize: false, allowLeftCollapse: true, space: 2, heightDiff: -1 });

      initLayout();
      $(window).resize(function () {
        initLayout();
      });

      $("#mainGrid").ligerGrid({
        columns: [
          { display: 'id', name: 'id', width:60,hide: true},
          { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; }},
          { display: '类型编码', name:'code', width:80},
          { display: '应用名称', name:'appModule.name', width:120},
          { display: '实体名称', name:'processEntity.entityName', width:120},
          { display: '类型名称', name:'typeName', align: 'left', width:120},
        ], url: _path + "/list/json?rnd=" + Math.random(), delayLoad: false, sortName:"code", sortOrder:"desc",
        pageSize: 30, pageSizeOptions: [20, 30, 50, 100], width: '100%', height: '100%', heightDiff: -1,
        enabledEdit: true
      });

      toolbar();
    });

    function toolbar() {
      var items = [];
      items.push({type: 'button', text: "增加", icon: 'add', click: function () { f_add(); }});
      items.push({type: 'button', text: "编辑", icon: 'edit', click: function () { f_edit(); }});
      items.push({type: 'button', text: "删除", icon: 'delete', click: function () { f_delete(); }});

      $("#toolbar").ligerToolBar({
        items: items
      });

      $("#mainGrid").ligerGetGridManager()._onResize();
    }

    //添加
    function f_add() {
        BAP.overrideSelectedTabItem(_path + '/edit', '创建流程类型');
    }

    //编辑
    function f_edit(rowId) {
      var manager = $("#mainGrid").ligerGetGridManager();
      var rows = manager.getCheckedRows();
      if (rows && rows.length > 0) {
        BAP.overrideSelectedTabItem(_path + '/edit?id=' + rows[0]['id'], '修改流程类型');
      }
    }

    //删除
    function f_delete() {
      var manager = $("#mainGrid").ligerGetGridManager();
      var rows = manager.getCheckedRows();
      if (rows && rows.length > 0) {
        var ids = [];
        $(rows).each(function () {
          ids.push(this.id);
        });

        BAP.confirm("流程类型删除不能恢复，确定删除？", function (yes) {
          if (yes) {
            BAP.openWaitting();
            $.ajax({
              url: _path + "/delete", type: "POST",dataType: 'json',
              data: {ids: ids.toString(), rnd: Math.random() },
              success: function (responseText) {
                BAP.closeWaitting();
                if (responseText.isError == false) {
                  BAP.showSuccess("删除成功!");
                  f_load();
                  f_reloadTree();
                } else {
                  BAP.showError(responseText.msg);
                }
              },
              error: function () {
                BAP.closeWaitting();
                BAP.showError('删除失败！');
              }
            });
          }
        })
      } else {
        BAP.showWarn("请选择");
      }
    }

    function f_load() {
      var manager = $("#mainGrid").ligerGetGridManager();
      manager.loadData(true);
    }
  </script>
</head>

<body style="padding: 0;overflow:hidden;">
<form id="searchForm" onsubmit="return false">
  <div id="layout1" style="margin: -1px">
    <div position="center">
      <div id="toolbar"></div>
      <div id="mainGrid"></div>
    </div>
  </div>
</form>
</body>
</html>